class User {
  User(
      {this.id,
      this.unId,
      this.jobNumber,
      this.username,
      this.sex,
      this.role,
      this.unit});
  int id;
  int unId;
  String jobNumber;
  String username;
  bool sex;
  String role;
  Unit unit;
  factory User.fromJson(Map<String, dynamic> json) {
    return User(
        id: json['id'],
        unId: json['unId'],
        jobNumber: json['jobNumber'],
        username: json['username'],
        sex: json['sex'],
        role: json['role'],
        unit: new Unit.fromJson(json['unit']));
  }
}

class Unit {
  int id;
  String unitName;

  Unit({this.id, this.unitName});
  factory Unit.fromJson(Map<String, dynamic> json) {
    return Unit(id: json['id'], unitName: json['unitName']);
  }
}

class Attendance {
  int id;
  String name;
  int unitId;
  String startTime;
  String endTime;
  DateTime setTime;

  Attendance(
      {this.id,
      this.name,
      this.unitId,
      this.setTime,
      this.startTime,
      this.endTime});
  factory Attendance.fromJson(Map<String, dynamic> json) {
    return Attendance(
        id: json['id'],
        unitId: json['unitId'],
        setTime: json['setTime'] == null ? null : DateTime.parse(json['setTime']),
        startTime: json['startTime'],
        endTime: json['endTime'],
        name: json['name']);
  }
}

class AttendanceList {
  final List<Attendance> attendances;

  AttendanceList({this.attendances});
  factory AttendanceList.fromJson(List<dynamic> json) {
    List<Attendance> attendances = new List<Attendance>();
    attendances = json.map((i) => Attendance.fromJson(i)).toList();

    return new AttendanceList(attendances: attendances);
  }
}

class Excuse {
  int id;
  int aid;
  int uid;
  int unid;
  String reason;
  String status;
  DateTime submitTime;
  DateTime startTime;
  DateTime endTime;

  Excuse(
      {this.id,
      this.aid,
      this.uid,
      this.unid,
      this.reason,
      this.status,
      this.submitTime,
      this.startTime,
      this.endTime});

  static String _status2String(int status){

    String s;

    switch (status){
      case 0:
        s = '已被否决';
        break;

      case 1:
        s = '已通过';
        break;

      case 2:
        s = '正在审核';
        break;

      case 3:
        s = '已被否决';
        break;

      case 4:
        s = '待审核';
        break;

      default:
        s = '发生异常';
    }

    return s;
  }

  factory Excuse.fromJson(Map<String, dynamic> json) {
    return Excuse(
        id: json['id'],
        uid: json['uid'],
        aid: json['aid'],
        unid: json['id'],
        startTime: DateTime.parse(json['startTime']),
        endTime: DateTime.parse(json['endTime']),
        submitTime: DateTime.parse(json['submitTime']),
        status: _status2String(json['status']),
        reason: json['reason']);
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        'startTime': startTime,
        'endTime': endTime,
        'submitTime': submitTime,
        'status': status,
        'reason': reason,
      };
}

class ExcuseList {
  final List<Excuse> excuses;

  ExcuseList({this.excuses});
  factory ExcuseList.fromJson(List<dynamic> json) {
    List<Excuse> excuses = new List<Excuse>();
    excuses = json.map((i) => Excuse.fromJson(i)).toList();

    return new ExcuseList(excuses: excuses);
  }
}

class Daily {
  int id;
  int uid;
  int aid;
  DateTime attendTime;
  DateTime generateTime;
  String status;
  Attendance attendance;

  Daily(
      {this.id,
      this.uid,
      this.aid,
      this.attendTime,
      this.generateTime,
      this.status,
      this.attendance
      });

  static String status2Str(int status){
    String s;

    switch (status){
      case 0:
        s = '未签到';
        break;

      case 1:
        s = '签到成功';
        break;

       default:
         s = '发生异常';
    }
    return s;
  }

  factory Daily.fromJson(Map<String, dynamic> json) {
    return Daily(
        id: json['id'],
        uid: json['uid'],
        aid: json['aid'],
        attendTime: json['attendTime'] == null ? null : DateTime.parse(json['attendTime']),
        generateTime: DateTime.parse(json['generateTime']),
        status: status2Str(json['status']),
        attendance: Attendance.fromJson(json['attendance'])
    );
  }
}

class DailyList {
  final List<Daily> dailies;

  DailyList({this.dailies});
  factory DailyList.fromJson(List<dynamic> json) {
    List<Daily> dailies = new List<Daily>();
    dailies = json.map((i) => Daily.fromJson(i)).toList();

    return new DailyList(dailies: dailies);
  }
}
